//
//  QuickGuideViewController.swift
//  CoolTennisBall
//
//  Created by CA on 16/5/16.
//  Copyright © 2016年 CoolLang. All rights reserved.
//

import UIKit

class QuickGuideViewController: UITableViewController {

    // MARK: Constants
    
    fileprivate struct Constants {
        static let HeaderHeight: CGFloat = 6.0
    }
    
    // MARK: View LifeCycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    // MARK: Private Method
    
    fileprivate func pageIndexFromIndexPathRow(_ indexPathRow: Int) -> Int {
        
        switch indexPathRow {
        case 0..<3: return 0
        case 3..<11: return indexPathRow - 2
        case 11: return indexPathRow - 3
        case 12,13: return 9
        default: return 0
        }
    }
    
    // MARK: UITableView Delegate
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        let controller = QuickGuidePageViewController()
        controller.modalTransitionStyle = .crossDissolve
        controller.modalPresentationStyle = .overFullScreen
        controller.currentIndexPage = pageIndexFromIndexPathRow(indexPath.row)
        present(controller, animated: true, completion: nil)
    }
    
    override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
        switch indexPath.row {
        case 0, 2, 10: return nil
        default: return indexPath
        }
    }
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return Constants.HeaderHeight
    }
    
    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return Constants.HeaderHeight
    }
    
    override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        
        cell.textLabel?.textColor = UIColor.white
        cell.textLabel?.highlightedTextColor = cell.textLabel?.textColor
        
        let selectionView = UIView(frame: CGRect.zero)
        selectionView.backgroundColor = UIColor(white: 0, alpha: 0.1)
        cell.selectedBackgroundView = selectionView
    }
}
